// asynchronous progress/cancel support
define(
  ["require", 
   "jquery", 
   "bip.cache", 
   "bip.base", 
   "bip.async",
   "validate",
   "validate_metadata",
   "validate_add_method",
   "data/global.userOrGroupData"
   ],
  function(require) {
    "use strict";

    var $ = require("jquery");
    var $bip = require("bip.base");
    var $userOrGroupData = require("data/global.userOrGroupData");
    
   jQuery.validator.addMethod("isGroupName", function(value, element, param){
	   var rName = /^[a-zA-Z][a-z0-9A-Z_]{2,19}$/;
	   
	   return this.optional(element) || rName.test(value);
   }, "名称只能以字符开始，只能包含字符、数值和下划线，在3-20个字符之间");
   
   jQuery.validator.addMethod("isNonDuplicateGN", function(value, element, param){
	   var groupName = $userOrGroupData.obtainGroup($.trim(value));
	   
	   var oldUserGroupName = param;
	   
	   
	   return this.optional(element) || (groupName === null || groupName.name === oldUserGroupName);
   }, "名称已经存在，请改用新名称");
   
   jQuery.validator.addMethod("charRangeLength", function(value, element, param) {       
	       var length = value.length;       
	       for(var i = 0; i < value.length; i++){       
	           if(value.charCodeAt(i) > 127){       
	           length++;       
	           }       
	       }       
	       return this.optional(element) || ( length >= param[0] && length <= param[1] );       
	   }, "请确保输入的值在3-20个字符之间(一个中文字算2个字符)");   
   
  }
);

